package com.linkoog.devtools.http.raw_index;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.linkoog.devtools.http.common.HttpMethod;
import com.linkoog.devtools.http.common.HttpServiceBody;
import com.linkoog.devtools.http.common.HttpServiceParam;
import com.linkoog.devtools.metadata.raw_index.MethodMetadata;
import com.linkoog.devtools.type.Type;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.function.Supplier;

@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class HttpServiceMethod extends MethodMetadata {

    // 全类名
    @Getter
    private final String classFullName;
    // 简短的类名
    @Getter
    private final String className;


    @Getter
    private final String sourceType;

    @Getter
    private final List<HttpMethod> httpMethods;
    @Getter
    private final List<String> mappingUrls;

    @Getter
    private final List<HttpServiceParam> headerParams;
    @Getter
    private final List<HttpServiceParam> pathParams;
    @Getter
    private final List<HttpServiceParam> queryParams;
    @Getter
    private final List<HttpServiceParam> fileParams;
    @Getter
    private final HttpServiceBody bodyParam;



    @JsonCreator
    public HttpServiceMethod(
            @JsonProperty("filePath")@NotNull String filePath,
            @JsonProperty("psiElementOffset") int psiElementOffset,
            @JsonProperty("name")@NotNull String name,
            @JsonProperty("paramTypes") List<Type> paramTypes,
            @JsonProperty("returnType") Type returnType,
            //自定义属性
            @JsonProperty("classFullName")@NotNull String classFullName,
            @JsonProperty("className") String className,
            @JsonProperty("sourceType")@NotNull String sourceType,
            @JsonProperty("httpMethods")@NotNull List<HttpMethod> httpMethods,
            @JsonProperty("mappingUrls")@NotNull List<String> mappingUrls,
            @JsonProperty("headerParams")@NotNull List<HttpServiceParam> headerParams,
            @JsonProperty("pathParams")@NotNull List<HttpServiceParam> pathParams,
            @JsonProperty("queryParams")@NotNull List<HttpServiceParam> queryParams,
            @JsonProperty("fileParams")@NotNull List<HttpServiceParam> fileParams,
            @JsonProperty("bodyParam") HttpServiceBody bodyParam

    ) {
        super(filePath, psiElementOffset, name, paramTypes, returnType);
        this.classFullName = classFullName;
        this.className = className != null ? className : "";
        this.sourceType = sourceType;
        this.httpMethods = httpMethods;
        this.mappingUrls = mappingUrls;
        this.headerParams = headerParams;
        this.pathParams = pathParams;
        this.queryParams = queryParams;
        this.fileParams = fileParams;
        this.bodyParam = bodyParam;
    }

    public HttpServiceMethod(
            @NotNull String filePath,
             int psiElementOffset,
            @NotNull String name,
            @NotNull Supplier<List<Type>> paramTypesSupplier,
            @NotNull Supplier<Type> returnTypeSupplier,
            //自定义属性
            @NotNull String classFullName,
            String className,
            @NotNull String sourceType,
            @NotNull List<HttpMethod> httpMethods,
            @NotNull List<String> mappingUrls,
            @NotNull List<HttpServiceParam> headerParams,
            @NotNull List<HttpServiceParam> pathParams,
            @NotNull List<HttpServiceParam> queryParams,
            @NotNull List<HttpServiceParam> fileParams,
            HttpServiceBody bodyParam

    ) {
        super(filePath, psiElementOffset, name, paramTypesSupplier, returnTypeSupplier);
        this.classFullName = classFullName;
        this.className = className != null ? className : "";
        this.sourceType = sourceType;
        this.httpMethods = httpMethods;
        this.mappingUrls = mappingUrls;
        this.headerParams = headerParams;
        this.pathParams = pathParams;
        this.queryParams = queryParams;
        this.fileParams = fileParams;
        this.bodyParam = bodyParam;
    }

}
